import sys

from PyQt6 import QtCore, QtWidgets
from PyQt6.QtGui import QIntValidator, QAction
from PyQt6.QtWidgets import QTextEdit, QApplication, QMainWindow

from dev.gui import Ui_main_win


class MainWindow(object):
    def setGui(self, main_win):
        main_win.setObjectName("main_win")
        main_win.setEnabled(True)
        main_win.resize(300, 600)
        main_win.setMinimumSize(QtCore.QSize(300, 600))
        main_win.setMaximumSize(QtCore.QSize(300, 600))
        main_win.setWindowTitle("框框的工具箱")
        self.main_content = QtWidgets.QWidget(parent=main_win)
        self.main_content.setObjectName("main_content")
        # tab 窗口
        self.tab_content = QtWidgets.QTabWidget(parent=self.main_content)
        self.tab_content.setGeometry(QtCore.QRect(5, 5, 290, 565))
        self.tab_content.setObjectName("tab_content")
        # 增幅
        self.zengfu_main()
        # 锻造
        self.duanzao_main()
        # 盒子
        self.hz_main()
        self.tab_content.setCurrentIndex(0)
        main_win.setCentralWidget(self.main_content)
        self.statusbar = QtWidgets.QStatusBar(parent=main_win)
        self.statusbar.setObjectName("statusbar")
        self.statusbar.setWindowTitle("个人测试")
        main_win.setStatusBar(self.statusbar)
        QtCore.QMetaObject.connectSlotsByName(main_win)

    def zengfu_main(self):
        self.zf = QtWidgets.QWidget()
        self.zf.setObjectName("zf")
        # 提示显示
        self.desc_text = QtWidgets.QTextBrowser(parent=self.zf)
        self.desc_text.setGeometry(QtCore.QRect(2, 2, 280, 150))
        self.desc_text.setObjectName("desc_text")
        desc_content = self.create_desc_text(
            ["1. 调整窗口大小为800*600", "2. 装备先放在物品栏第一格", "3. 先强化一次，增速",
             "4. 按CTRL+F9开始， CTRL+F10暂停","5. 成功识别图片，默认不需要，如果需要截图放在c://success.png,就截取成功那个框就行"])
        #print(desc_content)
        self.desc_text.setText(desc_content)

        self.zf_form = QtWidgets.QWidget(parent=self.zf)
        self.zf_form.setGeometry(QtCore.QRect(0, 155, 280, 350))
        self.zf_form.setObjectName("zf_form")
        # 保护卷个数输入框
        self.label = QtWidgets.QLabel(parent=self.zf_form)
        self.label.setGeometry(QtCore.QRect(10, 13, 70, 16))
        self.label.setObjectName("label")
        self.label.setText("保护卷个数:")
        # 保护卷个数输入框
        self.baohu_size_input = QtWidgets.QLineEdit(parent=self.zf_form)
        self.baohu_size_input.setGeometry(QtCore.QRect(88, 10, 190, 22))
        self.baohu_size_input.setObjectName("baohu_size_input")
        self.baohu_size_input.setPlaceholderText("保护卷个数，注意等级")
        self.baohu_size_input.setValidator(QIntValidator())
        self.label.setBuddy(self.baohu_size_input)
        # 成功最大次数标签
        self.label_2 = QtWidgets.QLabel(parent=self.zf_form)
        self.label_2.setGeometry(QtCore.QRect(10, 43, 70, 16))
        self.label_2.setObjectName("label_2")
        self.label_2.setText("成功次数:")

        # 成功最大次数输入框
        self.max_success_ct = QtWidgets.QLineEdit(parent=self.zf_form)
        self.max_success_ct.setGeometry(QtCore.QRect(88, 40, 190, 22))
        self.max_success_ct.setObjectName("max_success_ct")
        self.max_success_ct.setPlaceholderText("最多成功几次")
        self.max_success_ct.setValidator(QIntValidator())
        self.label_2.setBuddy(self.max_success_ct)

        # 已成功次数标签
        self.label_3 = QtWidgets.QLabel(parent=self.zf_form)
        self.label_3.setGeometry(QtCore.QRect(10, 73, 70, 16))
        self.label_3.setObjectName("label_3")
        self.label_3.setText("已成功次数:")
        # 已成功次数输入框
        self.has_success_ct = QtWidgets.QLineEdit(parent=self.zf_form)
        self.has_success_ct.setEnabled(True)
        self.has_success_ct.setGeometry(QtCore.QRect(88, 70, 190, 22))
        #self.has_success_ct.setReadOnly(True)
        self.has_success_ct.setObjectName("has_success_ct")
        self.has_success_ct.setText("0")
        self.label_3.setBuddy(self.has_success_ct)

        # 日志回显
        self.scrollArea = QtWidgets.QScrollArea(parent=self.zf_form)
        self.scrollArea.setGeometry(QtCore.QRect(5, 108, 271, 300))
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        self.zengfu_log_input = QTextEdit(parent=self.scrollArea)
        self.zengfu_log_input.setGeometry(QtCore.QRect(0, 0, 259, 249))
        self.zengfu_log_input.setObjectName("zengfu_log_input")
        self.zengfu_log_input.setReadOnly(True)

        self.scrollArea.setWidget(self.zengfu_log_input)

        self.tab_content.addTab(self.zf, "增幅")
        zf_action = QAction('增幅', self)
        zf_action.setShortcut('Ctrl+F9')  # 设置快捷键为Ctrl+Q
        zf_action.triggered.connect(self.zf_action_fun())  # 绑定触发动作到关闭窗口的槽函数
        zf_action_stop = QAction('增幅暂停', self)
        zf_action_stop.setShortcut('Ctrl+F10')  # 设置快捷键为Ctrl+Q
        zf_action_stop.triggered.connect(self.zf_action_stop_fun())  # 绑定触发动作到关闭窗口的槽函数

    def zf_action_fun(self):
        baohu_size_input_size = int(self.baohu_size_input.text())
        max_success_limit = int(self.max_success_ct.text())
        has_success = int(self.has_success_ct.text())
        log = f"开始增幅，保护卷数量：{baohu_size_input_size}, 增幅成功次数：{max_success_limit},已成功次数:{has_success}"
        self.zengfu_log_input.append(log)
        self.zengfu_log_input.verticalScrollBar().setValue(self.zengfu_log_input.verticalScrollBar().maximum())
        # 开始增幅

    def zf_action_stop_fun(self):
        pass
    def zf_action_reset_fun(self):
        pass

    def create_desc_text(self, desc: list):
        modul_html_before = """<html>
            <head>
            <meta />
                <meta charset="utf-8" />
                <style type="text/css"> 
                    p, li { white-space: pre-wrap; }
                    hr { height: 1px; border-width: 0; }
                    body { font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;}
                    p {margin:0 0 0 0; -qt-block-indent:0; text-indent:10px;}
                    .ct {margin:2px；border: 1px ∂ black}
                </style>
            </head>
            <body>
                <div class='ct'>
                    <p align="center" >使用说明</p>
                    <hr/>
            """
        modul_html_after="""
                </div>
            </body>
        </html>"""
        content = ""
        for line in desc:
            content = content + f"<p class='ct_line'>{line}</p>"
        #print(content)
        return modul_html_before + content + modul_html_after

    def duanzao_main(self):
        self.dz = QtWidgets.QWidget()
        self.dz.setObjectName("dz")
        # 锻造提示
        self.duanzao_text = QtWidgets.QTextBrowser(parent=self.dz)
        self.duanzao_text.setGeometry(QtCore.QRect(0, 0, 281, 101))
        self.duanzao_text.setObjectName("duanzao_text")
        desc_content = self.create_desc_text(["1. 装备先放在物品栏第一格", "2. 按CTRL+F7开始， CTRL+F8暂停"])
        self.duanzao_text.setText(desc_content)
        # 日志回显
        self.dz_log_scroll = QtWidgets.QScrollArea(parent=self.dz)
        self.dz_log_scroll.setGeometry(QtCore.QRect(0, 110, 281, 401))
        self.dz_log_scroll.setWidgetResizable(True)
        self.dz_log_scroll.setObjectName("dz_log_scroll")
        self.dz_log_cent = QTextEdit()
        self.dz_log_cent.setReadOnly(True)
        self.dz_log_cent.setGeometry(QtCore.QRect(0, 0, 279, 399))
        self.dz_log_cent.setObjectName("dz_log_cent")
        self.dz_log_scroll.setWidget(self.dz_log_cent)
        self.tab_content.addTab(self.dz, "锻造")

    def hz_main(self):
        self.hz = QtWidgets.QWidget()
        self.hz.setObjectName("hz")
        # 使用提示
        self.hz_desc = QtWidgets.QTextBrowser(parent=self.hz)
        self.hz_desc.setGeometry(QtCore.QRect(0, 0, 281, 125))
        self.hz_desc.setObjectName("hz_desc")
        desc_content = self.create_desc_text(
            ["1.盒子放在快捷键4", "2.选择盒子类型", "3.按CTRL+F5开始，CTRL+F6结束", "4. 购买各色大晶体100 CTRL+6",
             "5. 购买时空混乱宝石 CTRL+7"])
        self.hz_desc.setText(desc_content)
        # 龙盒选择
        self.max_hz = QtWidgets.QRadioButton(parent=self.hz)
        self.max_hz.setGeometry(QtCore.QRect(0, 130, 100, 20))
        self.max_hz.setObjectName("max_hz")
        self.max_hz.setText("龙盒max")
        self.hz_radio = QtWidgets.QRadioButton(parent=self.hz)
        self.hz_radio.setGeometry(QtCore.QRect(0, 149, 100, 20))
        self.hz_radio.setObjectName("hz_radio")
        self.hz_radio.setText("小龙盒")
        self.sly_redio = QtWidgets.QRadioButton(parent=self.hz)
        self.sly_redio.setGeometry(QtCore.QRect(0, 168, 100, 20))
        self.sly_redio.setObjectName("sly_redio")
        self.sly_redio.setText("赛利亚")
        self.tab_content.addTab(self.hz, "龙盒与无色")




if __name__ == "__main__":
    app = QApplication(sys.argv)
    main = QMainWindow()
    gui = MainWindow()
    gui.setGui(main)
    main.show()
    sys.exit(app.exec())
